#!/usr/bin/python
# -*- coding: utf-8 -*-

'''
Introduction to Programming in Java - An Interdisciplinary Approach

All book programs ported to Python by
Scott C. King (revisionx at {gee}ma1l <dot> c0m).

All program examples pass Pylint with a perfect 10.00 score.
Pylint:  http://www.pylint.org/


Creative Exercise 1.6.14 - Write a generator for Transition that
takes as input a page count N and a link count M and prints to standard
output N followed by M random pairs of integers from 0 to N-l.
(See Section 4.5 for a discussion of more realistic web models.)

Syntax:
python random_web.py 10 10
python random_web.py 10 10 | python transition.py
python random_web.py 10 10 | python transition.py | python markov.py 40


Notes:
For ease of use, this program is also included in the ch01/programs folder.

int(sys.argv[1]) == Integer.parseInt(args[0])

sys is a required import here in order to process command line arguments.
https://docs.python.org/2/tutorial/stdlib.html

'''

import sys
import random


def main():
    ''' Random web page/link generator for transition program '''

    page_count = int(sys.argv[1])
    link_count = int(sys.argv[2])

    print page_count
    pairs = '{} {}'

    for page in range(page_count):
        for _ in range(link_count):
            random_link = random.randint(0, link_count - 1)
            if page == random_link:
                continue
            else:
                print pairs.format(page, random_link),
        print


if __name__ == '__main__':
    main()
